package xin.codedream.codelog.model.global;

import lombok.Getter;
import lombok.Setter;
import xin.codedream.codelog.model.enums.ResponseEnum;

import java.io.Serializable;
import java.util.Map;

/**
 * 响应数据
 *
 * @author NGLSL
 * @date 2018/8/4
 */
@Getter
@Setter
public class ResponseData implements Serializable {

    /**
     * 默认编号
     */
    private static final Integer DEFAULT_CODE = ResponseEnum.ERROR_CODE.getCode();
    /**
     * 默认消息
     */
    private static final String DEFAULT_MESSAGE = ResponseEnum.ERROR_CODE.getMessage();
    /**
     * 返回码
     */
    private Integer code;
    /**
     * 消息
     */
    private String message;
    /**
     * 数据
     */
    private Map<String, Object> data;

    public ResponseData() {
        code = DEFAULT_CODE;
        message = DEFAULT_MESSAGE;
    }

    public ResponseData(ResponseEnum resp) {
        this.code = resp.getCode();
        this.message = resp.getMessage();
    }

    public ResponseData(ResponseEnum resp, Map<String, Object> data) {
        this.code = resp.getCode();
        this.message = resp.getMessage();
        this.data = data;
    }

    public ResponseData(Integer code, String message, Map<String, Object> data) {
        this.code = code;
        this.message = message;
        this.data = data;
    }

    public void setCodeMessage(ResponseEnum resp) {
        this.code = resp.getCode();
        this.message = resp.getMessage();
    }

    public void setCodeMessage(Integer code, String message) {
        this.code = code;
        this.message = message;
    }
}
